<?php
/**
 * Created by PhpStorm.
 * User: zy-l
 * Date: 2019/6/19
 * Time: 1:23 AM
 */

namespace App\HttpController\Api;

use App\Common\Exception\ThrowException;
use App\HttpController\Base;
use App\Model\InfoAdv;


/**
 * 获取广告
 * Class Infocase
 * @package App\HttpController\Api
 */
class Adv extends Base
{
    /**
     * 模型
     * @return InfoAdv
     */
    public function getInfoAdvModel()
    {
        return new InfoAdv();
    }

    /**
     * 获取广告列表
     * @return bool|void
     * @throws \EasySwoole\Mysqli\Exceptions\ConnectFail
     * @throws \EasySwoole\Mysqli\Exceptions\Option
     * @throws \EasySwoole\Mysqli\Exceptions\PrepareQueryFail
     * @throws \Throwable
     */
    public function index()
    {
        $where=[];
        $type=$this->getParam('type');
        if(empty($type)){
            throw  new ThrowException(ThrowException::ERROR_VALIDATION);
        }
        $where['type']=$type;
        return $this->writeJson('获取数据', $this->getInfoAdvModel()->getAll($this->getInfoAdvModel()->analysisWhere($where)));
    }
}